﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Continuum.Classes;

namespace Continuum
{
    public partial class EditProjector : Form
    {
        protected Projector proj;

        public EditProjector()
        {
            InitializeComponent();
        }

        // When 'SavingAs', allow them to change encryption settings
        public void SaveAsMode()
        {
            txtUniverseName.Enabled = true;
            pnlEncrypt.Visible = true;
        }

        public void SetProjectorReference(Projector projector)
        {
            proj = projector;

            if (proj.UniverseName == "") this.Text = "Please create a new Continuum";
            else txtUniverseName.Text = proj.UniverseName;
            numPastWindow.Value = proj.PastWindow;
            numFutureWindow.Value = proj.FutureWindow;
            numUpcomingDays.Value = proj.UpcomingDays;
            chkAutoRefreshMarket.Checked = proj.AutoRefreshMarket;
            numMarketRefreshRate.Value = proj.AutoRefreshRate;

            ActiveControl = txtUniverseName;
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            proj.UniverseName = txtUniverseName.Text;
            proj.PastWindow = (int) numPastWindow.Value;
            proj.FutureWindow = (int) numFutureWindow.Value;
            proj.UpcomingDays = (int)numUpcomingDays.Value;
            proj.AutoRefreshMarket = chkAutoRefreshMarket.Checked;
            proj.AutoRefreshRate = (int)numMarketRefreshRate.Value;

            if (pnlEncrypt.Visible)
            {
                MainForm.IsEncrypted = chkEncrypt.Checked;
                MainForm.EncryptPassword = txtEncryptPassword.Text;
            }

            MainForm.InstanceRef.HasChanged = true;

            Close();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void lnkOnlineHelp_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            System.Diagnostics.Process proc = new System.Diagnostics.Process();
            proc.StartInfo.UseShellExecute = true;
            proc.StartInfo.FileName = "http://project-continuum.com/OnlineHelp/AdvancedProjector.aspx";
            proc.Start();
        }
    }
}
